package com.liunian.subject.application.dto;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.liunian.subject.common.entity.PageInfo;
import com.liunian.subject.domain.entity.SubjectInfoBO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 提目表
 * @TableName subject_info
 */
@Data
@ApiModel(value = "题目信息DTO")
public class SubjectInfoDTO extends PageInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty(value = "题目名称")
    private String subjectName;

    @ApiModelProperty(value = "题目难度")
    private Integer subjectDifficult;

    @ApiModelProperty(value = "出题人")
    private String settleName;

    @ApiModelProperty(value = "题目类型 1单选 2多选 3判断 4简答")
    private Integer subjectType;

    @ApiModelProperty(value = "分数")
    private Integer subjectScore;

    @ApiModelProperty(value = "解析")
    private String subjectParse;

    @ApiModelProperty(value = "题目答案")
    private String subjectAnswer;

    @ApiModelProperty(value = "题目类别id列表")
    private List<Long> categoryIds;

    @ApiModelProperty(value = "题目标签id列表")
    private List<Long> labelIds;

    @ApiModelProperty(value = "答案信息列表")
    private List<SubjectAnswerDTO> optionList;

    @Data
    public static class SubjectAnswerDTO {
        @ApiModelProperty(value = "答案选项标识")
        private Integer optionType;

        @ApiModelProperty(value = "选项内容")
        private String optionContent;

        @ApiModelProperty(value = "是否正确")
        private Integer isCorrect;

        public SubjectInfoBO.SubjectAnswerBO dtoToBo() {
            SubjectInfoBO.SubjectAnswerBO bo = new SubjectInfoBO.SubjectAnswerBO();
            bo.setOptionType(this.optionType);
            bo.setOptionContent(this.optionContent);
            bo.setIsCorrect(this.isCorrect);
            return bo;
        }
    }

    public SubjectInfoBO dtoToBo() {
        SubjectInfoBO bo = new SubjectInfoBO();
        bo.setPageNo(this.getPageNo());
        bo.setPageSize(this.getPageSize());
        bo.setId(this.id);
        bo.setSubjectName(this.subjectName);
        bo.setSubjectDifficult(this.subjectDifficult);
        bo.setSettleName(this.settleName);
        bo.setSubjectType(this.subjectType);
        bo.setSubjectScore(this.subjectScore);
        bo.setSubjectParse(this.subjectParse);
        bo.setSubjectAnswer(this.subjectAnswer);
        bo.setCategoryIds(this.categoryIds);
        bo.setLabelIds(this.labelIds);
        if (CollectionUtil.isNotEmpty(this.optionList)) {
            bo.setOptionList(this.optionList.stream().map(SubjectAnswerDTO::dtoToBo).collect(Collectors.toList()));
        }
        bo.setCategoryId(this.categoryId);
        bo.setLabelId(this.labelId);
        bo.setLabelNames(this.labelNames);
        return bo;
    }

    @ApiModelProperty(value = "类别id")
    private Long categoryId;

    @ApiModelProperty(value = "标签id")
    private Long labelId;

    @ApiModelProperty(value = "标签名列表")
    private List<String> labelNames;

}